import { computed, reactive, ref } from "vue";
import { tableColumnMap } from "../data";
export default function InitHook() {
  const tableRef = ref<any>(null);
  const activeKey = ref<string>("5");
  const pageStat = ref<Base.GeneraDataType>({
    5: 0,
    6: 0,
    7: 0,
    8: 0,
    9: 0,
    "-5": 0,
    0: 0,
    "-2": 0
  });
  const searchForm = reactive<CustomerServiceWaybill.SearchForm>({
    companyIds: [],
    pageNum: 1,
    pageSize: 50,
    total: 0,
    keyWordsList: "",
    waybillNumList: "",
    fbaNumberList: "",
    transferOrderNumberList: "",
    bizIdList: [],
    followIdList: [],
    channelIdList: [],
    warehouseCodeList: [],
    warehousePropertyList: [],
    markList: [],
    notMark: "",
    customerIdList: [],
    makeInvoiceStatus: undefined,
    zipCode: "",
    countryRegionIdList: [],
    customsTaxesTypeList: [],
    customsDeclarationType: "",
    remark: "",
    innerRemark: "",
    createdTime: [],
    depositTime: [],
    outWarehouseBrokerIds: [],
    outWarehouseTime: [],
    warehouseNameList: [],
    pushOrderSuccess: "",
    questionType: "",
    beforePageNum: 0,
    saPageInfo: {},
    mergeNoList: ""
  });
  const tableData = ref<Array<CustomerServiceWaybill.ListRows>>([]);
  const saPageInfo = ref<Base.GeneraDataType>({});

  //上传文件的模版
  const upLoadTemplate = ref<number>(1);

  const dialogOpts = reactive<Base.DialogOpts>({
    title: "",
    width: "520px",
    component: "",
    visible: false,
    type: 1,
    passData: {}
  });
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "",
    width: "520px",
    component: "",
    visible: false,
    type: 1,
    passData: {}
  });
  const getPopupContainer = () => document.querySelector(".nav-header-page");

  const tableColumn = computed<Array<SuperTable.NestTableColumnItem | SuperTable.TableCoulmnItem>>(() => {
    return tableColumnMap[activeKey.value] || [];
  });
  const rowClassName = ({ row }: CustomerServiceWaybill.ListRows) => {
    // if (row.confirm_status === 3) return "red-row";
    // if (row.status === 1 && (row.charge_weight === 0 || row.charge_weight === null)) {
    //   return "yellow-row";
    // }
    // if (row.repeat_pick === 1) return "orange-row";
    if (row.status === 5 && (row.settlementWeight === 0 || row.settlementWeight === null)) return "yellow-row";
  };

  return {
    searchForm,
    tableData,
    dialogOpts,
    drawerOpts,
    tableRef,
    saPageInfo,
    activeKey,
    pageStat,
    getPopupContainer,
    tableColumn,
    rowClassName,
    upLoadTemplate
  };
}
